#!/usr/bin/python -S
"""
echo_test.py: Tests for echo.py
"""

__author__ = 'Andy Chu'


import unittest

import echo  # module under test


class EchoTest(unittest.TestCase):

  def setUp(self):
    pass

  def tearDown(self):
    pass

  def testParseToken(self):
    print echo.ParseToken('.foo')
    print echo.ParseToken('1')
    print echo.ParseToken('1.1')
    print echo.ParseToken('1.0e10')
    print echo.ParseToken('true')
    self.assert_(echo.OPEN_BRACKET is echo.ParseToken('['))

  def testParse(self):
    cases = [
        ['1'],
        ['true'],
        ['.string'],
        ['[', '1', '2', '3', ']'],
        ['[', '1', '[', '3', ']', ']'],
        ['[', '1', '{', '.a', '.b', '}', ']'],
        ['{', '.foo', '.bar', '.int', '3', '}'],
        ['{', '.foo', '.bar', '.list', '[', 'null', ']', '}'],
        ['{', '.mu', '.\xc2\xb5', '}'],  # mu in utf-8
        ['{', '.mu-bytes', '/\xc2\xb5', '}'],  # byte string
        ['{', '.mu-bytes', '/%c2%b5', '}'],  # percent-encoded byte string
        ['{', '.null', '/%00', '}'],  # percent-encoded byte string
        ['/%zz'],  # invalid escape, hm this is accepted literally by Python.
        ]
    for c in cases:
      print repr(echo.Parse(c))

    error_cases = [
        ['1', '2'],  # too many values, not in a list
        #['{', '1'],  # unclosed
        #['[', '1'],  # unclosed
        #['invalid'],  # invalid token
        ]

    for e in error_cases:
      print e
      print 'E', repr(echo.Parse(e))


if __name__ == '__main__':
  unittest.main()
